# Contributor: Thomas Kienlen <kommander@laposte.net>
# Maintainer: Thomas Kienlen <kommander@laposte.net>
pkgname=spotifyd
pkgver=0.3.3
pkgrel=1
pkgdesc="Open source Spotify client running as a UNIX daemon"
url="https://github.com/Spotifyd/spotifyd"
arch="all !riscv64 !s390x"
license="GPL-3.0-or-later"
makedepends="
	alsa-lib-dev
	cargo
	dbus-dev
	libogg-dev
	openssl-dev
	pulseaudio-dev
	"
pkgusers="spotifyd"
pkggroups="spotifyd"
install="spotifyd.pre-install"
subpackages="$pkgname-openrc"

source="https://github.com/Spotifyd/spotifyd/archive/v$pkgver/spotifyd-$pkgver.tar.gz
	spotifyd.initd
	spotifyd.conf
	"

prepare() {
	default_prepare

	# Optimize binary for size (10.7 MiB -> 4.8 MiB).
	cat >> Cargo.toml <<-EOF

		[profile.release]
		codegen-units = 1
		lto = true
		opt-level = "z"
		panic = "abort"
	EOF
}

build() {
	cargo build --release --locked --features pulseaudio_backend,dbus_mpris,dbus_keyring,rodio_backend
}

check() {
	cargo test --locked --target-dir=target
}

package() {
	install -D -m 755 target/release/spotifyd "$pkgdir/usr/bin/spotifyd"
	install -D -m 755 "$srcdir/spotifyd.initd" "$pkgdir/etc/init.d/spotifyd"
	install -D -m 660 -o spotifyd -g spotifyd "$srcdir/spotifyd.conf" "$pkgdir/etc/spotifyd.conf"
}

sha512sums="
bb8522a022ce1a4cd6a075b865f274ef4a6a5c6b37c44cb909637183cda1299d2218091ebec0f58b68233a74c17041d002557cad0137ee58ad123ec1587a921d  spotifyd-0.3.3.tar.gz
dd4664c5818af8de3439deedfecb2a9d6bd70ab41c3db57cf659d42d4071ffe47d137fa55d94009022472d5927668978df2e6236c574bbe35596fb386ef274a2  spotifyd.initd
3b431114226af7c67838bf860d07c4f4f661808142caadc9920d4268c1c3a89d61d99c310c13b3b4568dc6c10a5c95dfcb05a52f8551884a836a17b20b3ec06c  spotifyd.conf
"
